package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.CompanyApproSettingAddDTO;
import org.jsola.hr.dto.CompanyApproSettingUpdateDTO;
import org.jsola.hr.entity.CompanyApproSettingDO;
import org.jsola.hr.query.CompanyApproSettingQuery;
import org.jsola.hr.service.ICompanyApproSettingService;
import org.jsola.hr.vo.CompanyApproSettingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class CompanyApproSettingTestHelper extends BaseTestHelper {
    
    @Autowired
    private CompanyTestHelper companyTestHelper;
    @Autowired
    private ICompanyApproSettingService companyApproSettingService;

    /**
     * 生成add测试数据
     * @return CompanyApproSettingAddDTO
     */
    public CompanyApproSettingAddDTO getCompanyApproSettingAddDTO(){
        CompanyApproSettingAddDTO companyApproSettingAddDTO = new CompanyApproSettingAddDTO();
        companyApproSettingAddDTO.setCompanyId(companyTestHelper.saveCompanyExample().getId());
        companyApproSettingAddDTO.setApproFlowId(getRandomValue("varchar",32));
        companyApproSettingAddDTO.setIsOpen(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        return companyApproSettingAddDTO;
    }


    /**
     * 生成update测试数据
     * @return CompanyApproSettingUpdateDTO
     */
    public CompanyApproSettingUpdateDTO getCompanyApproSettingUpdateDTO(CompanyApproSettingVO companyApproSettingVO){
        return companyApproSettingService.selectDOById(companyApproSettingVO.getId(), SITE_ID).to(CompanyApproSettingUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return CompanyApproSettingQuery
     */
    public CompanyApproSettingQuery getCompanyApproSettingQuery() {
        CompanyApproSettingQuery companyApproSettingQuery = new CompanyApproSettingQuery();
        List<CompanyApproSettingDO> companyApproSettingDOList = companyApproSettingService.list(new CompanyApproSettingDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(companyApproSettingDOList)) {
            CompanyApproSettingDO companyApproSettingDO = companyApproSettingDOList.get(0);
            companyApproSettingQuery = companyApproSettingDO.to(CompanyApproSettingQuery.class);
        }
        return companyApproSettingQuery;
    }

    /**
     * 保存示例
     * @return CompanyApproSettingVO
     */
    public CompanyApproSettingVO saveCompanyApproSettingExample(){
        CompanyApproSettingAddDTO addDTO = this.getCompanyApproSettingAddDTO();
        CompanyApproSettingVO companyApproSettingVO = companyApproSettingService.save(addDTO,buildTokenUser());
        return companyApproSettingVO;
    }


}

